package com.company.service.impl;

import com.company.service.GetNovelTypesService;
import com.company.service.GetNovelsService;
import org.junit.Test;

import java.io.*;
import java.util.Scanner;
//小说
public class GetNovelsServiceImpl implements GetNovelsService {
    @Override
    public void execute() {

    }

    public void show(int choose) {
        Scanner input = new Scanner(System.in);
        Reader read = null;
        System.out.println("------------------小说列表开始--------------------");
        System.out.println("序号\t\t名称\t\t\t作者\t\t简介");
        if (choose == 1) {
            try {
                read = new FileReader("C:\\Users\\CM\\Desktop\\yanqing.txt");
                char[] chars = new char[1024];
                int n;
                while ((n = read.read(chars)) != -1) {
                    System.out.println(new String(chars, 0, n));
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    read.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else if (choose == 2) {
            try {
                read = new FileReader("C:\\Users\\CM\\Desktop\\wuxia.txt");
                char[] chars = new char[1024];
                int n;
                while ((n = read.read(chars)) != -1) {
                    System.out.println(new String(chars, 0, n));
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    read.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("-------------------小说列表结束------------------");
        System.out.print("\n-1.上传小说  0.返回上一级菜单 1.重新查看言情小说 2.重新查看武侠小说");
        System.out.println("\n输入小说序号阅读: ");
        switch (input.nextInt()) {
            case 0:
                GetNovelTypesService getNovelTypesService = new GetNovelTypesServiceImpl();
                getNovelTypesService.execute();
                break;
            case -1:
                GetNovelDataServiceImpl getNovelDataService = new GetNovelDataServiceImpl();
                getNovelDataService.execute();
                break;
            case 1:
                GetNovelsServiceImpl getNovelsService01 = new GetNovelsServiceImpl();
                getNovelsService01.show(1);//返回yanqing.txt小说
                return;
            case 2:
                GetNovelsServiceImpl getNovelsService02 = new GetNovelsServiceImpl();
                getNovelsService02.show(2);//返回wuxia.txt小说
                return;
            default:
                System.out.println("输入错误,请重新输入");
        }
    }
}
